package nk.mygraph;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.util.mxConstants;
import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxStylesheet;
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Hashtable;
import java.util.Map;


public class Test2 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        StackPane group = new StackPane();

        Scene scene = new Scene(group,900,900);

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();
        graph.getModel().beginUpdate();
        try{

            graph.foldCells(false);

            mxStylesheet stylesheet = new mxStylesheet();
            Hashtable<String,Object> style = new Hashtable<String, Object>();
            style.put(mxConstants.STYLE_SHAPE,mxConstants.SHAPE_CYLINDER);
            style.put(mxConstants.STYLE_OPACITY,50);
            style.put(mxConstants.STYLE_FONTCOLOR, "red");
            style.put(mxConstants.STYLE_INDICATOR_COLOR,"red");
            stylesheet.putCellStyle("ROUNDED",style);
            graph.insertVertex(parent, null, "正方形", 230, 10, 100, 100,"ROUNDED");

            graph.setStylesheet(stylesheet);
            System.out.println(graph.getCellStyle(stylesheet));

        }finally {
            graph.getModel().endUpdate();
        }

        final mxGraphComponent component = new mxGraphComponent(graph);
        component.setDragEnabled(false);

        SwingNode node = new SwingNode();
        node.setContent(component);



        group.getChildren().add(node);

        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
